const fs = require('fs')
const { Sequelize, DataTypes, Op } = require('sequelize')

const sequelize = new Sequelize('blog', 'postgres', 'Cxq1179233990.', {
    host: 'endoflife666.top',
    dialect: 'postgres'
})

let files = fs.readdirSync(__dirname)

let resFiles = files.filter(item => {
    return item.endsWith('.js') && item !== 'index.js'
})

let resObj = {}
resFiles.forEach(item => {
    let modelName = item.replace('.js', '')
    let tmpObj = require(__dirname + '/' + item)
    let tableName = modelName.toLowerCase()
    resObj[modelName] = sequelize.define(tableName, tmpObj)
});
resObj.Op = Op

resObj.sync = async () => {
    sequelize.sync({ force: true }).then(() => {
        resObj.Blog.bulkCreate([
            
        ])
    })
}

module.exports = resObj